<div style="width:680px; float:left; margin-right:5px" class="border_radius">

<?php

	include_once("../../coms/xl_tintuc.php");

	include_once("../../include/ckeditor/ckeditor.php");

	

	include_once("../../include/convert_link.php");

?>


<div class="content_right_title_admin">
	Thêm tin tức
</div>  
<div class="content_right_group_admin box_shadow" style="padding-bottom:5px">

        <table width="100%" cellspacing="0" style="padding-left:5px; padding-right:5px">

            <tr>

                <td>

                     <form name="fr_sua" method="post" action="trangchu.php?key=t_qltt" enctype="multipart/form-data">
 <div style="display:block; text-align:right">
					<div style="padding-top:10px; padding-bottom:10px; padding-left:10px" >
			 <input type="submit" name="bt_capnhat" value="Thêm mới" class="button medium blue"/>
         
             <input type="button" value="Quay lại" onclick="goBack()" class="button medium blue">
             

        </div>    
        </div>
                        <table width="98%" align="center" cellpadding="5px" cellspacing="10px">

                            <tr>

                                <td width="20%"><strong>Tiêu đề tin tức</strong> &nbsp;</td>

                                <td valign="top"><input type="text" name="txt_tieude" value="" size="83" class="border_radius"/></td>

                            </tr>

                         <tr>

                                <td width="20%" valign="top"><strong>Từ khóa</strong> &nbsp;</td>

                                <td>

                                    <!--Phuong - MOD - START - 06032012-->

                                    <textarea name="txt_tukhoa" style="width:530px; height:100px" class="border_radius"></textarea>	

                                    <!--Phuong - MOD - END - 06032012-->	

                                

                                </td>

                            </tr>     

                             <tr>

                                <td width="20%" valign="top"><strong>Mô tả</strong> &nbsp;</td>

                                <td>

                                    <!--Toan - ADD - START - 06032012-->

                                    <textarea name="txt_mota" style="width:530px; height:100px" class="border_radius"></textarea>	

                                    <!--Toan - ADD - END - 06032012-->	

                                

                                </td>

                            </tr>      

                        <tr>

                                <td><strong>Chọn hình</strong> &nbsp;</td>

                                <td><input type="file" name="up_hinh" class="border_radius"/></td>

                            </tr>

                            <tr>

                                <td colspan="2"><strong>Nội dung thu gọn</strong></td>

                            </tr>

                            <tr>

                                <td colspan="2">

                                    <?php 

                                        $CKEditor = new CKEditor();

                                        $CKEditor->basePath = '../../include/ckeditor/';

                                        $CKEditor->config['height'] = 100;

                                        $CKEditor->config['width'] =660;

                                        $CKEditor->editor("noidung_thugon","");  

                                    ?>	      

                                </td>

                            </tr>

                            <tr>

                                <td colspan="2"><strong>Nội dung đầy đủ</strong></td>

                            </tr>

                            <tr>

                                <td colspan="2">

                                    <?php 

                                        $CKEditor_new = new CKEditor();

                                        $CKEditor_new->basePath = '../../include/ckeditor/';

                                        $CKEditor_new->config['height'] = 500;

                                        $CKEditor_new->config['width'] =660;

                                        $CKEditor_new->editor("noidung_daydu","");  

                                    ?>	      

                                </td>

                            </tr>

                           

                            <tr>

                                <td colspan="2" align="center">

                                    <input type="submit" name="bt_capnhat" value="Thêm mới" class="button small blue"/>

                                    <input type="button" name="bt_lamlai" value="Làm lại"  onClick="javascript:window.location='trangchu.php?key=t_qltt'" class="button small blue"/>

                                </td>

                            </tr>

                        </table>

                    </form>

                </td>

            </tr>

        </table>

</div>

</div>

<?php

 

if(isset($_POST['bt_capnhat']))

{

	

	$tieude = $_POST['txt_tieude'];

	$tukhoa = $_POST['txt_tukhoa'];

	$file = $_FILES['up_hinh']['name'];

	

	

	$noidungthugon = $_POST['noidung_thugon'];

	$noidungdaydu = $_POST['noidung_daydu'];

	

	

	$manguoi = $_SESSION['MaNguoiDung'];

	$mota = $_POST['txt_mota'];	

	

	$timezone  = +7; //(GMT +7:00) 

	$ngaydang = gmdate("Y-m-d H:i:s", time() + 3600*($timezone+date("0"))); 

	$kq=array(0);

	$them = new xl_tintuc();

	if($file != NULL)

	{

		$kq=up_hinh();



		if($kq[2]==true)

		{

			$now = getdate();

			$tenhinhanh = "images/tintuc/".$kq[1];

			$ketqua = $them->them_tintuc($tieude,$noidungthugon,$noidungdaydu,$tukhoa,$tenhinhanh,$ngaydang,$manguoi,$mota);

			echo '<script type="text/javascript">

					alert("Thêm tin tức thành công!!!");				

				</script>';

			echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=qltt"  />';

		}

	}

	else

	{

		$ketqua = $them->them_tintuc1($tieude,$noidungthugon,$noidungdaydu,$tukhoa,$ngaydang,$manguoi,$mota);

		echo '<script type="text/javascript">

					alert("Thêm tin tức thành công!!!");				

				</script>';

		echo '<meta http-equiv="refresh" content="0;url=trangchu.php?key=qltt"  />';

	}

	

}



function up_hinh()

{

	$result = "";

	define('UPLOAD_DIR','../../images/tintuc/');

	define('MAX_FILES_SIZE',10000000);

	$file = str_replace(" ","_",$_FILES['up_hinh']['name']);

	//convert maximun size to KB

	$max = number_format(MAX_FILES_SIZE/1024,1)." KB";

	//create an array of permitted MIME types

	$premitted = array('image/gif','image/jpeg','image/pjpeg','image/png');

	//begin by assuming the file is unacceptable

	$sizeOK = false;

	$typeOK = false;

	$success = false;

	$kq=array(3);

	//Check that file is within the permitted size

	if($_FILES['up_hinh']['size']>0 && $_FILES['up_hinh']['size']<= MAX_FILES_SIZE)

	{

		$sizeOK = true;

	}

	

	//Check that file is within the permitted size

	foreach($premitted as $type)

	{

		if($type == $_FILES['up_hinh']['type'])

		{

			$typeOK = true;

			break;

		}

	}

	

	if($sizeOK && $typeOK)

	{

		switch($_FILES['up_hinh']['error'])

		{

			case 0:

				if(!file_exists(UPLOAD_DIR.$file))

				{			

					$success = move_uploaded_file($_FILES['up_hinh']['tmp_name'],UPLOAD_DIR.$file);

					$kq[1]=$file;

					$kq[0] = UPLOAD_DIR;

					

				}

				else

				{

					$now  = date("YmdHis",time());

					$file = $now.$file;

					$success = move_uploaded_file($_FILES['up_hinh']['tmp_name'],UPLOAD_DIR.$file);

					$kq[1]=$file;

					$kq[0] = UPLOAD_DIR;

				}

				if($success){

					$result = "$file upload thành công";

					//$result = "$file uploaded successfully";

				}

				else{

					$result = "Lỗi upload $file.Vui long thử lại.";

					//$result = "Error uploading $file.Please try again.";

				}

				break;

			case 3:

				$result = "Lỗi upload $file.Vui long thử lại.";

				//$result = "Error uploading $file.Please try again.";

			default:

				$result = "Lỗi hệ thống upload $file.Vui long thử lại.";

				//$result = "System error uploadding $file contact webmaster";

		}

	}

	elseif($_FILES['up_hinh']['error']==4){

		$result = "Chưa chọn file upload";

		//$result = "No file selected";

	}

	else{

		$result = "Lỗi file upload. Maximum size: $max. File upload phải là gif, jpg, png.";

		//$result ="$file cannot be uploaded. Maximum size: $max. Acceptable file types: gif, jpg, png.";

	}

	if($success == TRUE)

	{

		echo '<script language="javascript">

				window.alert("'.$result.'");

			</script>';

		//echo '<meta http-equiv="refresh" content="2;url=them_tintuc.php"  />';

	}

	else

	{

		echo '<script language="javascript">

				window.alert("'.$result.'");

			</script>';

		//echo '<meta http-equiv="refresh" content="2;url=them_tintuc.php"  />';

	}

	$kq[2] = $success;

	return $kq;

}



		

?>

